﻿namespace EasyGo.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using EasyGo.Common.Auth;
    using EasyGo.Common.Commands;
    using EasyGo.Common.Queries;
    using EasyGo.Logic;
    using EasyGo.Models;
    using EasyGo.Utils;

    public class TasksController : EasyGoJsonController
    {
        private readonly ITaskManager taskManager;

        private readonly ITaskQueries taskQueries;

        public TasksController(ITaskManager taskManager, ITaskQueries taskQueries)
        {
            this.taskManager = taskManager;
            this.taskQueries = taskQueries;
        }

        [HttpPost]
        public virtual ActionResult Add(CreateTaskCommand command)
        {
            var response = new JsonResponse();
            this.taskManager.CreateTask(command);
            return response.ToActionResult();
        }

        [HttpGet]
        public ActionResult List()
        {
            var response = new JsonResponse();
            response.Response = this.taskQueries.GetTasks(EasyGoPrincipal.Current.Id);
            return response.ToJsonResult();
        }
    }
}